package game.hud;

import game.engine.GameEngine;
import game.main.GameFrame;
import game.utility.ResourceUtility;
import game.utility.TextHandler;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.Image;

public class HeadsUpDisplay {

	private static final String PLAYERHEADIMAGE = "playerHead.png";
	public static final Font HUDFONT = new Font("Arial", Font.BOLD, 15);

	public static final int HEAD_WIDTH = 30;
	public static final int HEAD_HEIGHT = 30;

	private static final int LEFT_MARGIN = 40;
	private static final int BOTTOM_MARGIN = 40;
	private static final int PADDING = 10;

	private Image playerHeadImage;

	public HeadsUpDisplay() {
		this.playerHeadImage = ResourceUtility.getBufferedImage(ResourceUtility.getHUDImagePath(PLAYERHEADIMAGE));
	}

	private void drawExitText(Graphics2D g2d) {
		Font oldFont = g2d.getFont();
		Color oldColor = g2d.getColor();

		g2d.setFont(HUDFONT);
		g2d.setColor(Color.YELLOW);
		g2d.drawString(TextHandler.singleton().getSubtitleText("ONEXIT", new String[] { "ENTER" }), 20, GameFrame.singleton().getHeight() - HUDFONT.getSize());

		g2d.setFont(oldFont);
		g2d.setColor(oldColor);
	}

	public void drawToGraphics(Graphics2D g2d, int offsetX, int offsetY) {
		if (GameEngine.singleton().canPlayerExit()) {
			drawExitText(g2d);
		}
		int x = GameFrame.singleton().getWidth() - LEFT_MARGIN;
		int y = GameFrame.singleton().getHeight() - BOTTOM_MARGIN;
		for (int i = 0; i < GameEngine.singleton().getPlayer().getLives(); i++) {
			g2d.drawImage(playerHeadImage, x, y, HEAD_WIDTH, HEAD_HEIGHT, null);
			x -= HEAD_WIDTH + PADDING;
		}
	}

}